<?php
// Copyright 2012 @Wondershare
// $Id: Controller.php 437350 2012-08-04 10:58:24Z xuwh $
class Controller extends CController
{
    /**
     * @var string the default layout for the controller view. Defaults to '//layouts/column1',
     * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
     */
    public $layout = '//layouts/column1';
    /**
     * @var array context menu items. This property will be assigned to {@link CMenu::items}.
     */
    public $menu = array();
    /**
     * @var array the breadcrumbs of the current page. The value of this property will
     * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
     * for more details on how to specify this property.
     */
    public $breadcrumbs = array();
    public $metainfo = array();
    public $menupanel = array();
    public $leftmenu;
    public $allow_path = array();
    
    public function init ()
    {
        //判断左边菜单的参数
        if (! empty($_GET['menupanel'])) {
            $menupanel = explode('|', $_GET['menupanel']);
            $this->menupanel = $menupanel;
        } else {
            $this->menupanel = explode('|', 'content|news|index');
            $_GET['menupanel'] = 'content|news|index';
        }
        //获取菜单
        if (isset(Yii::app()->params['menulist'])) {
            $this->leftmenu = Yii::app()->params['menulist'];
        } else {
            $this->leftmenu = array();
        }
        //获取权限
        $allowUser = array(1,2,3,1473);
        $allowController = array('site');
        $cookie = Yii::app()->request->getCookies();
        if(isset($cookie['allow_path'])){
            $this->allow_path = explode('|',$cookie['allow_path']->value);
        }
        $curPath = Yii::app()->request->pathInfo;
        if(array_search($curPath,$this->allow_path)===false 
            && array_search(Yii::app()->user->id, $allowUser)===false
            && array_search(Yii::app()->controller->id, $allowController)===false){
                $login_url = Yii::app()->createUrl('site/login');
                echo "Permission deny!<a href='{$login_url}'>Relogin</a>";exit;
        }
    }
}